package com.cdream.basic.algorithm.leetcode.dp;

import java.util.Arrays;

/**
 * @author cdream
 * @date 6/1/21
 */
public class Question1744 {
    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Question1744().canEat(new int[]{7, 4, 5, 3, 8},
                new int[][]{{0, 2, 2}})));
    }
    public boolean[] canEat(int[] candiesCount, int[][] queries) {
        boolean[] answer = new boolean[queries.length];
        long[] candiesSum = new long[candiesCount.length];
        for (int i = 0; i < candiesCount.length; i++) {
            if (i == 0) {
                candiesSum[i] = candiesCount[i];
            }else{
                candiesSum[i] = candiesSum[i - 1] + candiesCount[i];
            }
        }

        for (int i = 0; i < queries.length; i++) {
            int[] indexQ = queries[i];
            // 吃糖数量的范围
            long minCandies = (long)indexQ[1] + 1;
            long maxCandies = ((long)(indexQ[1] + 1)) * indexQ[2];
            // 喜欢糖的前缀和
            long maxCount = candiesSum[indexQ[0]];
            long minCount = maxCount - candiesCount[indexQ[0]] + 1;
            // 判断交集
            if (minCandies > maxCount || maxCandies < minCount) {
                answer[i] = false;
            } else {
                answer[i] = true;
            }
        }
        return answer;
    }
}
